//
//  comBlueboxmoonPhoneWebLookup.m
//  WebLookup
//
//  Created by Daniel Hazelbaker on 10/27/10.
//  Copyright 2010 High Desert Church. All rights reserved.
//

#import "comBlueboxmoonPhoneWebLookup.h"


@implementation comBlueboxmoonPhoneWebLookup


//
// Retrieve my preferences, this is a read-only procedure.
//
+ (BMPreferences *)preferences
{
    return [BMPreferences preferencesWithIdentifier:@"com.blueboxmoon.snomPhone"];
}


//
// Set the default preferences.
//
+ (void)setDefaultPreferences
{
    BMPreferences   *prefs = [self preferences];


    if ([prefs valueForKey:kWebLookupWebAddressKey] == nil)
	[prefs setValue:@"" forKey:kWebLookupWebAddressKey];
}



#pragma mark BMPluginHandlerProtocol
//////////////////////////////////////////////////////////////////////////
//
// BMPluginHandlerProtocol
//
//////////////////////////////////////////////////////////////////////////


//
// The phone address lookup continues until the first plugin returns a
// non-nil result, indicating that it found the IP address (or host name)
// we are looking for.
//
- (NSString *)lookupPhoneAddress
{
    NSURLRequest    *request;
    NSData	    *data;
    
    
    request = [NSURLRequest requestWithURL:[NSURL URLWithString:[[[self class] preferences] valueForKey:kWebLookupWebAddressKey]]];
    data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    if (data != nil)
	return [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
	
    return nil;
}


@end
